

<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>课程管理</title>
    <link rel="stylesheet" href="/lib/layui/css/layui.css">
    <link rel="stylesheet" href="/css/attend/m/common.css">
    <link rel="stylesheet" href="/lib/layui/layui/css/eleTree.css">
    <link rel="stylesheet" href="/lib/layui/layui/css/layui.css">
    <script src="/lib/layui/layui/layui.js"></script>
    <script type="text/javascript" src="/lib/layui/layui/global.js"></script>
    <script type="text/javascript" src="/js/jquery/jquery-1.9.1.js"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery-1.8.3.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.ui.widget.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.iframe-transport.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.fileupload.js" type="text/javascript" charset="utf-8"></script>
    <script src="/js/ajaxupload.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jquery.form.min.js"></script>
    <script type="text/javascript" src="/js/common/fileupload.js"></script>
    <script src="/js/base/base.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/layui/layui/js/common.js" type="text/javascript" charset="utf-8"></script>
    <script src="/ui/lib/layui/layui/js/baseCode/base.js" type="text/javascript" charset="utf-8"></script>
    <style>
        html,body{
            width:100%;
            height:99%;
        }
        .layui-card-header{
            border-bottom: 1px solid #eee;
        }
        .mbox{
            /*padding: 8px;*/
            height:98%;
        }
        .inbox{
            padding: 5px;
            padding-right: 30px;
        }
        .deptinput{
            display: inline-block;
            width: 75%;
        }
        .layui-btn{
            margin-left: 10px;
        }
        .layui-btn .layui-icon{
            margin-right: 0px;
        }
        .layui-card{
            box-shadow:none
        }
        .red{
            color: red;
            font-size: 16px;
        }
        .layui-form-label{
            padding: 8px 15px;
        }
        .layui-card-body{
            display: flex;
        }
        .layui-lf{
            width: 255px;
            overflow-x: auto;
            height: 600px !important;
        }
        .layui-rt{
            width: calc(100% - 255px);
            margin-left: 6px;
            margin-top: -10px;
        }
        .treeTitle{
            display: flex;
            box-sizing: border-box;
            justify-content: center;
            align-items: center;
            width: 100%;
            height: 30px;
            background-color: #00a0e9;
            color: #fff;
            padding: 15px;
            position: relative;
        }
        .layui-nav-item,.layadmin-flexible{
            position: absolute;
            left: 5px;
            top: 23px;
            z-index: 9999999;
        }
        .rtfix{
            overflow-y: auto;
        }
        .bg{
            background-color: #F2F2F2;
        }
        .bgs{
            background-color: #F2F2F2;
        }
        /*滚动条样式*/
        .rtfix::-webkit-scrollbar {/*滚动条整体样式*/
            width: 4px;     /*高宽分别对应横竖滚动条的尺寸*/
            height: 4px;
        }
        .rtfix::-webkit-scrollbar-thumb {/*滚动条里面小方块*/
            border-radius: 5px;
            -webkit-box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
            background: rgba(0,0,0,0.2);
        }
        .rtfix::-webkit-scrollbar-track {/*滚动条里面轨道*/
            -webkit-box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
            border-radius: 0;
            background: rgba(0,0,0,0.1);}
        .eleTree{
            cursor: pointer;
        }
        .layui-table-view .layui-table td, .layui-table-view .layui-table th{
            padding: 3px 0;
        }
        .layui-tab-title{
            height: 30px;
        }
        .layui-tab-title li{
            height: 36px;
            margin-top: -5px;
        }
        .layui-tab layui-tab-card{
            margin-top: -4px;
        }
        .layui-tab-card>.layui-tab-title .layui-this:after {
            border-width: 0px;
        }
        .baseinfo td{
            padding: 5px 2px;
        }
        .active{
            display: none;
        }
        .layui-inline{
            width:47%;
        }
        .layui-form-label{
            width:125px;
        }
        #search .layui-inline{
            width:41%;
        }
        #search .layui-form-label{
            width:70px;
        }


    </style>
</head>
<body>

<div class="mbox">

    <div class="layui-card">
        <div class="layui-card-body" style="padding-left: 6px;">
            <div class="layui-lf rtfix">
                <button class="layui-btn layui-btn-sm" lay-event="add" style="width: 105px;margin-bottom:10px;" id="courseType">课程阶段管理</button>
                <div class="treeTitle" id="equip" dataType="0" >课程阶段

                </div>
                <%--<div id="test1"></div>--%>
                <div class="panel-body">
                    <%--<div id="test9" class="demo-tree demo-tree-box"></div>--%>
                    <div class="eleTree ele1" lay-filter="data1"></div>
                </div>
            </div>
            <div class="layui-rt" style="position: relative">
                <%--<div class="layui-nav-item layadmin-flexible" id="fixed" lay-unselect="">--%>
                    <%--<a href="javascript:;" layadmin-event="flexible" title="侧边伸缩">--%>
                        <%--<i class="layui-icon layui-icon-shrink-right" id="LAY_app_flexible"></i>--%>
                    <%--</a>--%>
                <%--</div>--%>
                    <form class="layui-form" id="search"  action="">
                    <div class="layui-form-item" style="margin-bottom:0px;margin-top:10px;">
                        <div class="layui-inline">
                            <label class="layui-form-label">课程名称</label>
                            <div class="layui-input-inline" style="">
                                <input type="text" name="courseName" id="courseName" placeholder="" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">课程类型</label>
                            <div class="layui-input-inline" style="">
                                <select name="courseType" id="courseTypes" lay-verify="required">
                                    <option value="">请选择</option>
                                    <option value="0">线上</option>
                                    <option value="1">线下</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">讲师</label>
                            <div class="layui-input-inline" style="">
                                <input type="text" name="courseLecturer" id="courseLecturer" placeholder="" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <%--<div class="layui-inline">--%>
                            <%--<label class="layui-form-label">状态</label>--%>
                            <%--<div class="layui-input-inline" style="">--%>
                                <%--<select name="courseState" id="courseState" lay-verify="required">--%>
                                    <%--<option value="">请选择</option>--%>
                                    <%--<option value="1">已发布</option>--%>
                                    <%--<option value="0">未发布</option>--%>
                                <%--</select>--%>
                            <%--</div>--%>
                        <%--</div>--%>
                        <button type="button" id="searchBtn" class="layui-btn" style="    margin-top: -5px;margin-left: 33px;">搜索</button>
                    </div>
                    </form>
                <table id="Settlement" lay-filter="SettlementFilter"></table>

            </div>
            <div class="layui-card" id="opens" style="height:95%;display: none"><form class="layui-form" method="post" enctype="multipart/form-data" id="ajaxform" method="post" action="/signIn/importSignIn">
                <div class="layui-form-item" style="margin-top: 10px;">

                    <div class="layui-inline" style="width:98%">
                        <label class="layui-form-label" style="width:138px">导入模板下载:</label>
                        <div class="layui-input-inline" style="margin-top: 7px;">
                            <a href="javascript:;" id="download" style="color:#1E9FFF;">点击模板下载</a>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item" style="margin-top: 10px;">

                    <div class="layui-inline"  style="width:98%">
                        <label class="layui-form-label" style="width:138px">选择文件:</label>
                        <div class="layui-input-inline" style="">
                            <input type="file" id="file" name="file" enctype="multipart/form-data"  >
                        </div>
                    </div>
                </div>

            </form></div>
        </div>
    </div>

</div>
<script type="text/html" id="toolbar">

    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="add" style="width: 70px" id="addEq">新增</button>
        <%--<button class="layui-btn layui-btn-sm" lay-event="import" style="width: 70px" id="import">签到导入</button>--%>
        <%--<button class="layui-btn layui-btn-sm" lay-event="pedit" style="width: 70px" >批量修改</button>--%>
        <%--<button class="layui-btn layui-btn-sm" lay-event="pdel" style="width: 70px" onclick="doRemoveBatch()">批量删除</button>--%>
        <%--<button class="layui-btn layui-btn-sm" lay-event="import" style="width: 70px">导入</button>--%>
    </div>
</script>

<script type="text/html" id="toolbars">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="add" style="width: 70px" href="/equipCert/addvice">新增</button>
        <button class="layui-btn layui-btn-sm" lay-event="pedit" style="width: 70px">批量修改</button>
    </div>
</script>

<script type="text/html" id="barOperation">
    <a class="layui-btn layui-btn-xs" lay-event="fabu" id="fabu" style="display: none">发布</a>
    <a class="layui-btn layui-btn-xs" lay-event="courseCon" class="courseCon" id="courseCon">课程排课</a>
    <%--<a class="layui-btn layui-btn-xs" lay-event="courseCon" id="erwei">二维码</a>--%>
    <a class="layui-btn layui-btn-xs" lay-event="edit" id="edit1">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" >删除</a>
    <a class="layui-btn  layui-btn-xs" id="person" style="display: none" lay-event="person" >人员信息</a>
    <%--<a class="layui-btn  layui-btn-xs" lay-event="import" >签到导入</a>--%>
</script>
<script type="text/javascript">
    var courseId="";  //课程
    var category;
   var parentId='';
    var el
        ,aldata
        ,newstr='<div class="iptbox mnodec" pid="">'+
        '<input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="序号" class="layui-input pnul">'+
        '<input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="名称" class="layui-input shorts">'+
        '<input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="备注" class="layui-input longs">'+
        '<div class="btnls">'+
        '<button type="button" class="layui-btn layui-btn-primary layui-btn-sm limsAdd"><i class="layui-icon"></i></button>'+
        '<button type="button" class="layui-btn layui-btn-primary layui-btn-sm limsDel"><i class="layui-icon"></i></button>'+
        '</div>'+
        '</div>';
    var resultTypeData='';
    var a ="";
    $('.rtfix').css('max-height',autodivheight()-55)
    var tableObj;
    layui.use(['table','layer','laydate','form','element','eleTree'], function(){
        var table = layui.table;
        var layer = layui.layer;
        var form = layui.form;
        var laydate = layui.laydate;
        var eleTree = layui.eleTree;
        var element = layui.element;
        var $ = layui.jquery;
        //第一个实例
        tableObj=table.render({
            elem: '#Settlement'
//            defaultToolbar: ['filter', {
//                title: '提示' //标题
//                ,layEvent: 'LAYTABLE_TIPS' //事件名，用于 toolbar 事件中使用
//                ,icon: 'layui-icon-tips' //图标类名
//            }]
            ,url: '/trCourse/showAll' //数据接口
            ,page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['prev', 'page', 'next',  'skip','count','limit',]//自定义分页布局
                ,limits:[5,10,15,20,25,30,35,40,45,50]
                ,limit:5
                ,first: false //不显示首页
                ,last: false //不显示尾页
            } //开启分页
            ,toolbar:'#toolbar'
            ,cols: [[ //表头
                {type: 'checkbox' }
                ,{type: 'numbers', title: '序号'}
                ,{field: 'courseId', title: 'id',hide:true}
                ,{field: 'courseName', title: '课程名称'}
                ,{field: 'courseType', title: '课程类型',templet:function(d){
                   if(d.courseType == 0){
                       return '线上'
                   }else{
                       return '线下'
                   }
                    }}
                ,{field: 'courseLecturer', title: '讲师'}
                ,{field: 'endTime', title: '课程截止时间'}
                ,{field: 'courseIntroduce', title: '课程介绍'}
                ,{field: 'studyCount', title: '点击次数'}
                ,{fixed: 'right',width:400,title: '操作',align:'center', toolbar: '#barOperation'}
            ]]

            ,limit:10
            ,done:function(res) {
                for(var i=0;i<res.data.length;i++){
                        if(res.data[i].courseType== 0){
                            // $('.courseCon').hide()
//                            $('tr[data-index="'+i+'"]').find('#courseCon').hide()
                            $('tr[data-index="'+i+'"]').find('#fabu').show()
                            $('tr[data-index="'+i+'"]').find('#person').show()
                            if(res.data[i].courseState == '0'){
                                $('tr[data-index="'+i+'"]').find('#fabu').text('发布')
                            }else{
                                $('tr[data-index="'+i+'"]').find('#fabu').text('取消发布')
                            }
                        }else{
                            // $('.courseCon').show()
//                            $('tr[data-index="'+i+'"]').find('#courseCon').show()
                            $('tr[data-index="'+i+'"]').find('#fabu').hide()
                            $('tr[data-index="'+i+'"]').find('#person').hide()
                        }

                }
            }
        });
        function undefind_nullStr(value) {
            if(value==undefined){
                return ""
            }
            return value
        }
        $('#searchBtn').click(function(){

            var currentPage = 1;
            table.reload('Settlement',{
                url : '/trCourse/showAll?courseName='+$('#courseName').val()+'&courseType='+$('#courseTypes').val()+'&courseLecturer='+$('#courseLecturer').val(),
                data:{
                    page:currentPage
                },
                page:{
                    curr:currentPage
                }
            })
        })
        //监听复选框事件
        table.on('checkbox(SettlementFilter)', function(obj){
            var tr = obj.tr[0];
            if(obj.checked){
                $(tr).addClass('bgs')
            }else{
                $(tr).removeClass('bgs').removeClass('bg')
            }
        });


        // 初始化渲染 树形菜单
        el = eleTree.render({
            elem: '.ele1',
            showLine:true,
            // url:'/equipmentType/showParentEquipmentType',
            url:'/trCourseStage/showParent',
            lazy: true,
            load: function(data,callback) {
                // console.log(data)
                // $.post('/equipmentType/showChildEquipmentType?equipTypeId='+data.id,function (res) {
                $.post(' /trCourseStage/showChild?courseStage='+data.courseStage,function (res) {
                    callback(res.data);//点击节点回调
                })
            },
            done:function (data) { //渲染完成回调
                aldata = data.data
            }
            ,highlightCurrent: true,
        });
        // 节点点击事件
        eleTree.on("nodeClick(data1)",function(d) {

            var obj = d.data.currentData
            var pid = obj.equipTypePid;
            parentId=obj.courseStage;
          //  alert(courseTypeId);
         /*       $.post('/equipmentType/showEquipmentTypeById?equipTypeId=' + obj.id, function (res) {
                var obj = res.data
                    , str;
            })*/
         // console.log(d);

            var currentPage = 1
            table.reload('Settlement',{
                url : '/trCourse/showAll?courseStage='+obj.courseStage,
                data:{page:currentPage},
                page:{
                    curr:currentPage
                }
            })

        });

        table.on('toolbar(SettlementFilter)', function(obj){
            switch(obj.event){
                case 'add':
                    editAdd(0, 0);
                    break;
                case 'import':

                    break;
            };
        });
// 编辑/删除操作
        table.on('tool(SettlementFilter)', function(obj){//注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象
             courseId= data.courseId;
            var courseName= data.courseName;
            var courseType = data.courseType;
            var teacher=data.courseLecturer;
            var urlTitle=' /trCourse';
            if(layEvent === 'del'){ //删除
                // layer.confirm('确认删除', function(index){
                publicDeletes(urlTitle+"/delete",courseId+"",tableObj,table);
                //向服务端发送删除指令
                // });
            } else if(layEvent === 'edit'){ //编辑
                editAdd(1,courseId);
            }else if(layEvent === 'courseCon'){

                if($(this).text()=='二维码'){
                    window.location.href = '/course/courseCon?courseId='+courseId+'&courseLecturer='+encodeURI(teacher)+'&courseName='+encodeURI(courseName)+'&courseType='+courseType+'&type=1';
                }else{
                    // layer.open({
                    //     type:2,
                    //     area:['90%','80%'],
                    //     content:''
                    // })
                    $.popWindow('/course/courseCon?courseId='+courseId+'&courseType='+courseType+'&type=0','课程排课', '', '', '1200px', '800px')

                }

            }else if(layEvent === 'fabu'){
                var data = {courseId:courseId}
                if($(this).text() == '发布'){
                    data.courseState = '发布'
                }else{
                    data.courseState = '取消发布'
                }
                $.ajax({
                    url:'/trCourse/changeState',
                    type:'post',
                    data:data,
                    dataType:'json',
                    success:function(res){
//                        var currentPage = 1
                        table.reload('Settlement',{
                            url : '/trCourse/showAll?courseSources='+parentId,
//                            data:{page:currentPage},
//                            page:{
//                                curr:currentPage
//                            }
                        })
                    }
                })
            }else if(layEvent === 'import'){
                layer.open({
                    type: 1,
                    skin: 'layui-layer-rim', //加上边框
                    area: ['500px', '300px'], //宽高
                    shadeClose:true,
                    title: '导入',
                    maxmin: true,
                    btn: ['<div style="background:none;border:none;color:#fff" id="lay-submit">确定</div>', '取消'],
                    content:jQuery("#opens"),
                    success:function(){
                        $('#download').click(function(){
                            window.location.href=encodeURI('/file/jdProject/签到信息模板 .xlsx')
                        })
                    },
                    yes:function(index){
                        if ($('input[name="file"]').val() == "") {
                            layer.msg("请选择要导入的文件！", {icon: 2});
                            return false;
                        }
                        var body = layer.getChildFrame('body', index);
                        var formData = new FormData();
                        formData.append("file",document.getElementById("file").files[0]);
                        $('#ajaxform').ajaxSubmit({
                            dataType: 'json',
                            data:{
                                courseId:courseId,
                                courseName:courseName
                            },
                            success:function (res) {
                                    layer.msg(res.msg, {icon: 1});
                            }
                        })
                        // $.ajax({
                        //     url:'/signIn/importSignIn',
                        //     dataType: 'json',
                        //     type: 'POST',
                        //     data: formData,
                        //     cache: false,
                        //     processData: false,  // 不处理数据
                        //     contentType: false,
                        //     success: function(r){
                        //         if(r.flag == 0){
                        //             alert("导入成功！");
                        //             vm.reload();
                        //
                        //         }else{
                        //             alert(r.msg);
                        //         }
                        //     }
                        // });
                        layer.close(index);

                    }
                })
            }
            // 点击 线上 人员信息 弹窗
            else if(layEvent === 'person'){
                layer.open({
                    type: 2,
                    title:'人员信息',
                    area:['90%','80%'],
                    content: '/course/OnlinePersonInformation',
                });
            }
        });
        $('#fixed').click(function(e){
            e.stopPropagation();
            $('table').width('100%')
            if($(this).attr('dataType')!=1){
                $('.layui-lf').fadeOut();
                $('.layui-rt').animate({width: '100%'});
                $(this).attr('dataType','1');
            }else{
                $('.layui-lf').fadeIn();
                $('.layui-rt').animate({width: '84%'});
                $(this).attr('dataType','0');
            }

        })




//        删除
        function publicDeletes(url,ids,tableIns,table){
            layer.confirm('确定要删除吗?', {icon: 3, title:'提示'}, function(index){
                var data={
                    courseId:ids
                }
                var res=toAjaxT(url,data);
                layer.msg(res.msg)
                if(res.code==0){
                    try {
                        if (ids.substring(ids.length - 1) == ",") {
                            ids = ids.substring(0, ids.length - 1);
                        }
                        var dataSize = ids.split(",");
                        var dataAll = table.cache[tableIns.config.id];
                        if (dataAll.length == dataSize.length) {
                            //得到当前页
                            var page = $(".layui-laypage-skip .layui-input").val();

                            if (page > 1) {
                                tableIns.reload({
                                    page: {
                                        curr: page - 1 //重新从第 1 页开始
                                    }}
                                );
                            }else{
                                tableIns=tableIns.reload();
                            }
                        } else {
                            tableIns=tableIns.reload();
                        }
                    } catch (e) {
                        tableIns.reload();
                    }
                }
                layer.close(index);
            });
        }
//编辑添加layer
        function editAdd(type,courseId) {
            var title="编辑";
            if(type==0){
                title="新增课程信息";
                if(parentId==''){
                    $.layerMsg({
                        content:'请选择课程阶段',
                        icon:6
                    });
                    return false;
                }
                <%--
                if(courseTypeId==''||parentId==0){
                    $.layerMsg({
                        content:'请选择课程类别',
                        icon:6
                    });
                    return false;
                }
                --%>
            }
            var index =  layer.open({
                type: 1,
                skin: 'layui-layer-rim', //加上边框
                area: ['900px', '80%'], //宽高
                title:title,
                shadeClose:true,
                maxmin: true,
                btn: ['<div style="background:none;border:none;color:#fff" id="lay-submit">确定</div>', '取消'],
                content: '<div class="layui-card"><form class="layui-form" id="ajaxform1" action="">' +
                '<div class="layui-form-item" style="margin-top: 10px;">\n' +
                ' \n' +
                '  <div class="layui-inline">\n' +
                '    <label class="layui-form-label">课程名称<span style="color:red">*</span></label>\n' +
                '    <div class="layui-input-inline" style="">\n' +
                '      <input type="text" name="courseName" placeholder="" autocomplete="off" class="layui-input">\n' +
                '      <input type="hidden" value="'+parentId+'" name="courseStage" placeholder="" autocomplete="off" class="layui-input">\n' +
/*
                    '      <input type="hidden" value="'+category+'" name="courseCategory" placeholder="" autocomplete="off" class="layui-input">\n' +
*/
                '    </div>\n' +
                '  </div>\n' +
                '  \n' +
                '  <div class="layui-inline">\n' +
                '    <label class="layui-form-label">课程类型<span style="color:red">*</span></label>\n' +
                '    <div class="layui-input-inline" style="">\n' +
                '       <select name="courseType" lay-filter="courseType" lay-verify="required">\n' +
                '        <option value="">请选择</option>\n' +
                '        <option value="0">线上</option>\n' +
                '        <option value="1">线下</option>\n' +
                '      </select>\n' +
                '    </div>\n' +
                '  </div>\n' +
                '  \n' +
                '</div>' +

                '<div class="layui-form-item">\n' +
                ' \n' +
                '  <div class="layui-inline">\n' +
                '    <label class="layui-form-label">讲师 <span style="color:red">*</span></label>\n' +
                '    <div class="layui-input-inline" style="">\n' +
                '      <input type="text" name="courseLecturer" placeholder="" autocomplete="off" class="layui-input">\n' +
                '    </div>\n' +
                '  </div>\n' +
                '  <div class="layui-inline time" style="display:none">\n' +
                '    <label class="layui-form-label">课程截止时间 <span style="color:red">*</span></label>\n' +
                '    <div class="layui-input-inline" style="">\n' +
                '      <input type="text" name="endTime" placeholder="" autocomplete="off" class="layui-input endTime">\n' +
                '    </div>\n' +
                '  </div>\n' +
                '</div>' +
                '<div class="layui-form-item">\n' +
                ' \n' +
                '  <div class="layui-inline" style="width: 98%;">\n' +
                '    <label class="layui-form-label">课程介绍 <span style="color:red">*</span></label>\n' +
                '    <div class="layui-input-inline" style="width: 71%;">\n' +
                '      <textarea name="courseIntroduce" placeholder="请输入内容" class="layui-textarea"></textarea>\n' +
                '    </div>\n' +
                '  </div>\n' +
                '</div>' +
                '<div class="layui-form-item hide">\n' +
                ' \n' +
                '  <div class="layui-inline" style="width: 98%;">\n' +
                '    <label class="layui-form-label">视频地址 </label>\n' +
                '    <div class="layui-input-inline" style="width: 71%;">\n' +
                '      <textarea name="videoAddress" placeholder="请输入内容" class="layui-textarea"></textarea>\n' +
                '    </div>\n' +
                '  </div>\n' +
                '</div>' +
                '<div class="layui-form-item hide">\n' +
                ' \n' +
                '  <div class="layui-inline" style="width: 98%;">\n' +
                '    <label class="layui-form-label">要求学习时长 <span style="color:red">*</span> </label>\n' +
                '    <div class="layui-input-inline" style="width: 71%;">\n' +
                '      <input name="learningTime" style="width:95%;float: left;" placeholder="请输入要求学习时长" class="layui-input"><span style="float:left;padding-top: 8px;">分钟</span>\n' +
                '    </div>\n' +
                '  </div>\n' +
                '</div>' +
                '<div id="Attachment" style="margin-left: 165px;margin-bottom: 10px;"></div>'+
                    '<input type="hidden" name="attachmentId" autocomplete="off" class="layui-input">' +
                '<input type="hidden" name="attachmentName" autocomplete="off" class="layui-input">'+
                '<input type="hidden" name="attachmentId2" autocomplete="off" class="layui-input">' +
                '<input type="hidden" name="attachmentName2" autocomplete="off" class="layui-input">'+
                '</form><form class="layui-form" id="uploadimgform"  target="uploadiframe"  action="/upload?module=train"  method="post" >\n' +
                '<div class="layui-form-item">\n' +
                ' \n' +
                '  <div class="layui-inline" style="">\n' +
                '    <label class="layui-form-label">图片封皮上传 <span style="color:red">*</span></label>\n' +
                '    <div class="layui-input-inline" style="position:relative">\n' +
                    '<button id="uploadimg" type="button" class="layui-btn">附件上传</button>'+
                '<input type="file" multiple="multiple" name="file"  id="uploadinputimg"  class="w-icon5" style="position: absolute;opacity: 0;width: 95px;left:10px;height:40px;filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0)">\n' +
                '    </div>\n' +
                '  </div>\n' +
                '</div>' +

                '</form>' +
                '<div id="Attachment2" style="margin-left: 165px;margin-bottom: 10px;"></div>'+

                '<form class="layui-form" id="uploadimgform"  target="uploadiframe"  action="/uploadVideo?module=train"  method="post" >' +
                '                    <div class="layui-form-item">'+

                '                      <div class="layui-inline" style="">' +
                '                        <label class="layui-form-label">课程附件上传 </label>' +
                '                       <div class="layui-input-inline" style="position:relative">' +
                '                    <button id="uploadimg" type="button" class="layui-btn">附件上传</button>' +
                '                    <input type="file" multiple="multiple" name="file"  id="uploadinput"  class="w-icon5" style="position: absolute;opacity: 0;width: 95px;left:10px;height:40px;filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0)">' +
                '                        </div>' +
                '                      </div>' +
                '                    </div>' +

                '                    </form></div>',
                success:function (res) {
                    form.render()
                    fileuploadFn('#uploadinputimg',$('#Attachment'));
                    fileuploadFn('#uploadinput',$('#Attachment2'));
                    //附件删除
                    $('#Attachment').on('click','.deImgs',function(){
                        var data=$(this).parents('.dech').attr('deUrl');
                        var dome=$(this).parents('.dech');
                        deleteChatment(data,dome);
                    })
                    laydate.render({
                        elem: '.endTime', //指定元素
                        format: 'yyyy-MM-dd HH:mm:ss'
                    });
                    form.on('select(courseType)', function(data){
                          if(data.value==0){
                              $('.hide').show()
                              $('.time').show()
                          }else{
                              $('.hide').hide()
                              $('.time').hide()
                          }
                            if(data.value==''){
                                $('.time').hide()
                            }
                    });




                    if(type == 1){
                        $.ajax({
                            url:'/trCourse/showDetils?courseId='+courseId,
                            type:'get',
                            dataType:'json',
                            success:function(res){
                                var str = ''
                                $('#ajaxform1 input[name="courseName"]').val(undefind_nullStr(res.object.courseName)) //课程名称
                                $('#ajaxform1 input[name="courseStage"]').val(undefind_nullStr(res.object.courseStage)) //
                                if(res.object.courseType==0){
                                    $('.time').show()
                                    $('#ajaxform1 input[name="endTime"]').val(undefind_nullStr(res.object.endTime))
                                }else{
                                    $('.time').hide()
                                }

                                $('#ajaxform1 select[name="courseType"]').val(undefind_nullStr(res.object.courseType)) //课程类别
                                $('#ajaxform1 input[name="courseLecturer"]').val(undefind_nullStr(res.object.courseLecturer)) //讲师

                                $('#ajaxform1 [name="courseIntroduce"]').val(undefind_nullStr(res.object.courseIntroduce)) //课程介绍
                                $('#ajaxform1 [name="videoAddress"]').val(undefind_nullStr(res.object.videoAddress)) //课程介绍
                                $('#ajaxform1 [name="learningTime"]').val(undefind_nullStr(res.object.learningTime)) //课程介绍

                                if(res.object.courseType==1){
                                    $('.hide').hide()
                                }else{
                                    $('.hide').show()
                                }


                                if(res.object.attachmentList.length>0){
                                    for(var i=0;i<res.object.attachmentList.length;i++){
                                        str+='<div class="dech" deUrl="'+res.object.attachmentList[i].attUrl+'"><a href="<%=basePath %>download?'+res.object.attachmentList[i].attUrl+'" NAME="'+res.object.attachmentList[i].attachName+'*"><img style="width:16px;" src="/img/file/cabinet@.png"/>'+res.object.attachmentList[i].attachName+'</a><img class="deImgs" style="margin-left:5px;cursor: pointer;" src="/img/file/icon_deletecha_03.png"/><input type="hidden" class="inHidden" value="'+res.object.attachmentList[i].aid+'@'+res.object.attachmentList[i].ym+'_'+res.object.attachmentList[i].attachId+',"></div>';
                                    }
                                }else{
                                    str='';
                                }
                                $('#Attachment').html(str)
                                var str2=''
                                if (res.object.attachmentList1.length > 0) {
                                    for (var i = 0; i < res.object.attachmentList1.length; i++) {
                                        str2 += '<div class="dech" deUrl="' + res.object.attachmentList1[i].attUrl + '"><a href="<%=basePath %>download?' + res.object.attachmentList1[i].attUrl + '" NAME="' + res.object.attachmentList1[i].attachName + '*"><img style="width:16px;" src="/img/file/cabinet@.png"/>' + res.object.attachmentList1[i].attachName + '</a><img class="deImgs" style="margin-left:5px;cursor: pointer;" src="/img/file/icon_deletecha_03.png"/><input type="hidden" class="inHidden" value="' + res.object.attachmentList1[i].aid + '@' + res.object.attachmentList1[i].ym + '_' + res.object.attachmentList1[i].attachId + ',"></div>';
                                    }
                                } else {
                                    str2 = '';
                                }
                                $('#Attachment2').html(str2)
                                //附件删除
                                $('#Attachment2').on('click','.deImgs',function(){
                                    var data=$(this).parents('.dech').attr('deUrl');
                                    var dome=$(this).parents('.dech');
                                    console.log(data)
                                    console.log(dome)
                                    deleteChatment(data,dome);
                                })
                                form.render();

                            }
                        })
                    }
                },
                yes:function (index,layero) {


                    var attachmentId='';
                    var attachmentName='';
                    var attachmentId2='';
                    var attachmentName2='';
                    for(var i=0;i<$('#Attachment .inHidden').length;i++){
                        attachmentId += $('#Attachment .inHidden').eq(i).val();
                    }
                    for(var i=0;i<$('#Attachment .inHidden').length;i++){
                        attachmentName += $('#Attachment a').eq(i).attr('NAME');
                    }
                    for(var j=0;j<$('#Attachment2 .inHidden').length;j++){
                        attachmentId2 += $('#Attachment2 .inHidden').eq(j).val();
                    }
                    for(var k=0;k<$('#Attachment2 .inHidden').length;k++){
                        attachmentName2 += $('#Attachment2 a').eq(k).attr('NAME');
                    }
                    $('input[name="attachmentId"]').val(attachmentId)
                    $('input[name="attachmentName"]').val(attachmentName)
                    $('input[name="attachmentId2"]').val(attachmentId2)
                    $('input[name="attachmentName2"]').val(attachmentName2)


                    if(type == 0){
                        $('#ajaxform1').attr('action','/trCourse/add ')
                    }else {

                        $('#ajaxform1').attr('action','/trCourse/change?courseId='+courseId)
                    }
                    //该判断为 当用户未填写课程名称时  显示提示信息
                     if($('#ajaxform1 input[name="courseName"]').val()==''){
                         $.layerMsg({content:'请填写课程名称',icon:2});
                         return false;
                     }
                    //该判断为 当用户未选择课程类型时  显示提示信息
                    if($("#ajaxform1 select option:checked").text()=='请选择'){
                        $.layerMsg({content:'请选择课程类型',icon:2});
                        return false;
                    }
                    // if($('#ajaxform1 input[name="courseType"]').val()==''){
                    //     $.layerMsg({content:'请选择课程类型',icon:2});
                    //     return false;
                    // }
                    if($('#ajaxform1 input[name="courseLecturer"]').val()==''){
                        $.layerMsg({content:'请选择讲师',icon:2});
                        return false;
                    }
                    //该判断为 当用户未填写课程介绍时  显示提示信息
                    if($('#ajaxform1  textarea').val()==''){
                        $.layerMsg({content:'请填写课程介绍',icon:2});
                        return false;
                    }
                    if($('#ajaxform1 input[name="attachmentId"]').val()==''){
                        $.layerMsg({content:'请选择课程封面',icon:2});
                        return false;
                    }
                    if($('.hide').css('display')!='none'){
                        if($('#ajaxform1 input[name="learningTime"]').val()==''){
                            $.layerMsg({content:'请填写视频要求学习时长',icon:2});
                            return false;
                        }
                    }
                    // if($('#ajaxform1 input[name="attachmentId2"]').val()==''){
                    //     $.layerMsg({content:'请上传课程附件',icon:2});
                    //     return false;
                    // }

                    $('#ajaxform1').ajaxSubmit({
                        dataType: 'json',
                        type: 'post',
                        success:function (res) {
                           layer.closeAll();
//                           var currentPage =1;
                            table.reload('Settlement',{
                                url : '/trCourse/showAll?courseStage='+parentId,
//                                data:{page:currentPage},
//                                page:{
//                                    curr:currentPage
//                                }
                            })
                        }
                    })


                },
                btn2:function(index,layero){

                },
                cancel:function(index,layero){

                }
            });
        }
    });


    $('#courseType').click(function(){
        layer.open({
            type: 2,
            skin: 'layui-layer-rim', //加上边框
            area: ['500px', '80%'], //宽高
            shadeClose:true,
            title:'课程管理',
            maxmin: true,
            btn: ['<div style="background:none;border:none;color:#fff" id="lay-submit">确定</div>', '取消'],
            content:'/train/stageType',
            yes:function(){
                window.location.reload();
            }
        })
    })
    function deleteChatment(data,element){

        layer.confirm('<fmt:message code="workflow.th.que" />？', {
            btn: ['<fmt:message code="global.lang.ok" />','<fmt:message code="depatement.th.quxiao" />'], //按钮
            title:"<fmt:message code="notice.th.DeleteAttachment" />"
        }, function(){
            //确定删除，调接口
            $.ajax({
                type:'get',
                url:'/delete',
                dataType:'json',
                data:data,
                success:function(res){

                    if(res.flag == true){
                        layer.msg('<fmt:message code="workflow.th.delsucess" />', { icon:6});
//                                     var file = $('[name="file"]')
//                                     file.after(file.clone().val(""));
//                                     file.remove();
                        element.remove();
                    }else{
                        layer.msg('<fmt:message code="lang.th.deleSucess" />', { icon:6});
                    }
                }
            });

        }, function(){
            layer.closeAll();
        });
    }

    //将毫秒数转为yyyy-MM-dd格式时间
    function format(t) {
        var  str = "";
        var nnow = new Date(t);
        var year = nnow.getFullYear();
        var month = nnow.getMonth()+1;
        var day = nnow.getDate();
        str = year+"-"+month+"-"+day;
        return str;
    }
    //获取当前时间  年月日
    function nowformat() {
        var  nstr = "";
        var now = new Date();
        var nyear = now.getFullYear();
        var nmonth = now.getMonth()+1;
        var nday = now.getDate();
        if(nmonth<10){
            nmonth = "0"+nmonth;
        }
        if(nday<10){
            nday = "0"+nday;
        }
        nstr = nyear+"-"+nmonth+"-"+nday;
        return nstr;
    }


</script>
<script>





</script>

</body>



</html>
